//
//  ChainShareManager.m
//  Chain
//
//  Created by zhaosh on 2018/4/18.
//  Copyright © 2018年 zhaosh. All rights reserved.
//
#import "ChainShareManager.h"


@implementation ChainShareManager
static ChainShareManager *chainShareManager;

+(ChainShareManager *)shareChainShareManager{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        chainShareManager=[[ChainShareManager alloc] init];
    });
    return chainShareManager;
}

- (void)shareWebPageToPlatformType:(UMSocialPlatformType)platformType
                      andShareTitle:(NSString *)shareTitle
                      andShareText:(NSString *)shareText
                       andShareUrl:(NSString *)shareUrl
                   andSuccessBlock:(void (^) (id data))successBlock
                      andFailBlock:(void (^) (NSError *error))failBlock{
    //创建分享消息对象
    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
    //创建网页内容对象
    UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:shareTitle descr:shareText thumImage:[UIImage imageNamed:@"AppIcon"]];
    //设置网页地址
    shareObject.webpageUrl =shareUrl;
    //分享消息对象设置分享内容对象
    messageObject.shareObject = shareObject;
    //调用分享接口
    [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
        if (error) {
            NSLog(@"************Share fail with error %@*********",error);
            failBlock(error);
        }else{
            NSLog(@"response data is %@",data);
            successBlock(data);
            
        }
    }];
}

@end
